package pers.ijfxu.testngext.dataprovider.impl;

import java.util.Map;

import pers.ijfxu.testngext.utils.JsonUtils;

/**
 * 存放bean的excel文本迭代器
 *
 * @author ijfxu  
 * @since 2021/5/23 14:06
 * @see TxtBeanIterator
 */
public class ExcelBeanIterator extends ExcelIterator {
    private Class<?>[] types;

    /**
     * 构造器
     *
     * @param dataFile excel数据文档路径
     * @param types    迭代器返回值类型
     * @author ijfxu 
     * @since 2021/5/23 14:06
     */
    public ExcelBeanIterator(String dataFile, Class<?>... types) {
        super(dataFile);
        this.types = types;
    }

    /**
     * 解析数据，提供继承重写
     *
     * @param data excel map 数据
     * @return Object[] map数据组
     * @author ijfxu 
     * @since 2021/5/23 14:06
     */
    public Object[] parseData(Map<String, Object> data) {
        Object[] dataArr = new Object[1];
        if (types.length == 1) {
            dataArr[0] = JsonUtils.parseObj(data, types[0]);
        } else {
            dataArr[0] = data;
        }
        return dataArr;
    }
}
